package cn.edu.seu.ssny.config.scheduler;

import cn.edu.seu.ssny.service.IDeviceDataStdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class DataBaseScheduler {

    @Autowired
    private IDeviceDataStdService deviceDataStdService;

    /**
     * 每天凌晨 0点8分
     * 删除 年记录表 月记录表 日记录表 不满足该表中存储的数据
     */
    @Scheduled(cron = "0 8 0 * * ?")
    public void removeFromDataBase() {
        log.info(new Date() + "开始删除数据");
        deviceDataStdService.deleteFromYear();
        deviceDataStdService.deleteFromMonth();
        deviceDataStdService.deleteFromDay(10);
        deviceDataStdService.deleteFromHour(2);
        log.info(new Date() + "成功删除数据");
    }
}
